package edu.jmu.transaction;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository("accountDao")
public class AccountDaoImpl implements AccountDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public void transferFrom(String user, int money) {
		String sql = "update account set money = money-? where name=?";
		jdbcTemplate.update(sql,money,user);

	}

	@Override
	public void transferTo(String user, int money) {
		String sql = "update account set money = money+? where name=?";
		jdbcTemplate.update(sql,money,user);

	}
	
	@Override
	public void displayAllAccount(){
		String sql = "select * from account";
		List<Account> accountList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<Account>(Account.class));
		for (Account account : accountList) {
			System.out.println(account);
		}
	}

}
